from django.db import models


class JobChannelGroup(models.Model):
    """频道组"""
    name = models.CharField(max_length=20, verbose_name='频道组名')

    class Meta:
        db_table = 'tb_channel_group'
        verbose_name = '职业频道组'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class JobCategory(models.Model):
    """职业类别"""
    name = models.CharField(max_length=20, verbose_name='名称')
    parent = models.ForeignKey('self', related_name='subs', null=True, blank=True, on_delete=models.CASCADE,
                               verbose_name='父类别')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_job_category'
        verbose_name = '职业类别'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.name


class JobChannel(models.Model):
    """职业频道"""
    group = models.ForeignKey(JobChannelGroup, verbose_name='频道组名')
    category = models.ForeignKey(JobCategory, on_delete=models.CASCADE, verbose_name='一级职业类别')
    sequence = models.IntegerField(verbose_name='组内顺序')
    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        db_table = 'tb_job_channel'
        verbose_name = '职业频道'
        verbose_name_plural = verbose_name

    def __str__(self):
        return self.category.name
